package com.design_mode;

/**
 * Created by dustaple on 8/4/14.
 */
public class StrategyPattern {
    public static void main(String[] args) {

        SContext context = new SContext(new DiscountStrategy());
        context.sellStrategy();
        context.setStrategy(new Over200Minus30Strategy());
        context.sellStrategy();
    }
}

interface AbstractStrategy {
    void excuteStategy();
}

class DiscountStrategy implements AbstractStrategy {

    @Override
    public void excuteStategy() {
        System.out.println("全场8折.");
    }
}

class Over200Minus30Strategy implements AbstractStrategy {
    @Override
    public void excuteStategy() {
        System.out.println("满200减30.");
    }
}

class SContext {
    AbstractStrategy strategy;

    SContext(AbstractStrategy strategy) {
        this.strategy = strategy;
    }

    public void setStrategy(AbstractStrategy strategy) {
        this.strategy = strategy;
    }

    public void sellStrategy() {
        strategy.excuteStategy();
    }
}